package com.qishenyuan.competition.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qishenyuan.competition.common.PageUtil;
import com.qishenyuan.competition.dto.ResumeReq;
import com.qishenyuan.competition.model.Resume;
import com.qishenyuan.competition.dao.ResumeDao;
import com.qishenyuan.competition.service.ResumeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qishenyuan.competition.vo.ResumeResp;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 简历表 服务实现类
 * </p>
 *
 * @author qishenyuan
 * @since 2025-04-05
 */
@Service
public class ResumeServiceImpl extends ServiceImpl<ResumeDao, Resume> implements ResumeService {

    @Override
    public IPage<ResumeResp> getResumeList(ResumeReq resumeReq) {
        IPage<Resume> iPage = PageUtil.toIPage(resumeReq.getPageQuery());
        QueryWrapper<Resume> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        IPage<Resume> iPageResult = baseMapper.selectPage(iPage, queryWrapper);
        return iPageResult.convert(resume -> ResumeResp.buildVo(resume));
    }

    @Override
    public ResumeResp getResume(Integer id) {
        Resume resume = baseMapper.selectById(id);
        if(resume == null){
            return null;
        }
        Integer newViews=resume.getViews()+1;
        resume.setViews(newViews);
        baseMapper.updateById(resume);
        return ResumeResp.buildVo(resume);
    }
}
